import http from './http'

export default {
  getQuestions ({ gid, page = 0, category = '', ...params }) {
    let q = http.buildQuery(params)
    return http.get(`api/question?_format=json&group_id=${gid}&page=${page}&question_category=${category}&${q}`)
  },

  getQuestion (id) {
    return http.get(`api/question/${id}?_format=json`)
  },

  getQuestionAnswers (id) {
    return http.get(`api/question/${id}/answer?_format=json`)
  },

  postQuestion (data) {
    return http.post(`api/question`, data)
  },

  updateQuestion ({ id, ...data }) {
    return http.patch(`api/question/${id}`, data)
  },

  deleteQuestion (id) {
    return http.delete(`api/question/${id}`)
  },

  getQuestionAnswer (id) {
    return http.get(`api/question/0/answer/${id}?_format=json`)
  },

  postQuestionAnswer ({ id, ...data }) {
    return http.post(`api/question/${id}/answer`, data)
  },

  patchQuestionAnswer ({ qid, aid, ...data }) {
    return http.patch(`api/question/${qid}/answer/${aid}`, data)
  },

  deleteQuestionAnswer (qid, aid) {
    return http.delete(`api/question/${qid}/answer/${aid}`)
  }
}
